import os
from PIL import Image


imgTypes=[".png",".jpg",".bmp"]
dir=input("输入路径(事前在D盘建立SPLIST作为输出文件夹)：")
for root,dirs,files in os.walk(dir):
    for afile in files:
        ffile=root+"/"+afile
        if ffile[ffile.rindex("."):].lower() in imgTypes:
            newfilename="0"*(8-len(afile))+afile
            print(ffile)

            img = Image.open(ffile)
            x,y=img.size
            img2 = img.crop((0, 0, x/2, y))
            img2.save("d:/split/"+newfilename.split(".")[0]+"-2."+newfilename.split(".")[1])

            img2 = img.crop((x/2, 0, x, y))
            img2.save("d:/split/" + newfilename.split(".")[0] + "-1." + newfilename.split(".")[1])
            # os.remove(ffile)